<template>
	<view style="height: 100vh;">
		<scroll-view style="height: 100%;" scroll-y="true" @scrolltolower="loadMore" :refresher-enabled="true"
			:refresher-triggered="triggered" @refresherrefresh="refresherrefresh">
			<view v-for="(item,index) in list" :key="index" @click="details(item)"
				style="margin: 16rpx;padding: 20rpx;background: #fff;border-radius: 10rpx;">
				<view style="color: #aaa;font-size: 24rpx;display: flex;justify-content: space-between;">
					<view>
						{{item.createDate}}
					</view>
					<view>
						{{statusName(item.kpStatus)}} > 
					</view>
				</view>
				<view style="margin-top: 10px;display: flex;justify-content: space-between;">
					<view>
						电子发票
					</view>
					<view>
						{{item.isum}}元
					</view>
				</view>
			</view>
			<view class="loadmore" v-if="list.length">
				<u-loadmore :status="loadStatus"></u-loadmore>
			</view>
			<view class="page-box" v-if="!list.length"
				style="min-height: 50vh;width: 100%;display: flex;align-items: center;justify-content: center;">
				<view>
					<u-empty text="暂无开票历史信息!" mode="list"></u-empty>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import util from '@/common/fire.js'
	export default {

		data() {
			return {
				focus: false,
				remarks: '',
				list: [],
				triggered: false,
				loadStatus: 'loadmore',
				query: {
					pageNo: 1,
					pageSize: 20,
				},
			}
		},
		onLoad() {
			this.query.pageNo = 1;
			this.loadList();
		},
		methods: {
			statusName(type){
				let status = ''
					if(type==1){
						status = '申请中'
					}else if(type==2){
						status = '已开票'
					}else if(type==3){
						status = '开票中'
					}else if(type==9){
						status = '已取消'
					}
				return status
			},
			details(item) {
				uni.navigateTo({
					url: '/pages/btdm/index/user/invoice/details?id=' + item.id,
				})
			},
			async refresherrefresh() {
				this.triggered = true
				this.query.pageNo = 1;
				await this.loadList()
				this.triggered = false
			},
			loadList(type) {
				this.query.cusCode=this.vuex_basCus.code
				// this.query.createBy=this.vuex_user.userCode
				this.$u.api.shop.fpApplylistData(this.query).then(res => {
					if (res.list.length < 20 || res.list.length == 0) {
						this.loadStatus = "nomore";
					}
					var list = res.list;
					if (type == "add") {
						for (var i = 0; i < list.length; i++) {
							this.list.push(list[i])
						}
					} else {
						this.list = list;
					}
				})

			},
			loadMore() {
				this.loadStatus = "loading";
				setTimeout(() => {
					this.query.pageNo += 1;
					this.loadList("add");
				}, 100);
			},

		},


	}
</script>

<style lang="scss" scoped>
	
</style>